<?php
/**
 * 后台父类控制器，后台所有控制器继承该控制器
 * User: paul
 * Date: 2017/2/20 0020
 * Time: 18:20
 */

namespace backend\controllers;

use Yii;
use yii\web\Controller;
use yii\helpers\Url;


class BaseController extends Controller
{

    /**
     * 标记当前地址供后面跳转
     */
    public function setForward()
    {
        Yii::$app->getSession()->setFlash('__forward__', $_SERVER['REQUEST_URI']);
    }

    /**
     * 获取之前保存的跳转地址
     * @param string $default 默认的跳转地址
     * @return mixed|string
     */
    public function getForward($default = '')
    {
        $default = $default ?: Url::toRoute([Yii::$app->controller->id . '/index']);

        if (Yii::$app->getSession()->hasFlash('__forward__')) {
            return Yii::$app->getSession()->getFlash('__forward__');
        } else {
            return $default;
        }
    }

}